package com.controller;

import com.domain.Activity;
import com.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@Controller
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @RequestMapping("/getUI")
    public String doGetUI(){
        return "activity";
    }


    @GetMapping("/findAll")
    @ResponseBody
    public ArrayList<Activity> doFindAll(){
        return activityService.findActivityAll();
    }

    @RequestMapping("/insertActivity")
    @ResponseBody
    public String doInsertActivity(Activity activity){
        System.out.println(activity);
        return "添加成功啦--->" + activityService.insertActivity(activity);
    }


    @RequestMapping("/deleteById/{id}")
    @ResponseBody
    public String doDeleteById(@PathVariable Integer id){
        return "删除成功啦--->" + activityService.deleteById(id);
    }

    @RequestMapping("/updateById")
    @ResponseBody
    public String doUpdateById(@RequestBody Activity activity){
        return "修改成功啦--->" + activityService.updateById(activity);
    }


    @RequestMapping("selectOne/{id}")
    @ResponseBody
    public Activity doSelectOne(@PathVariable Integer id){
        System.out.println(activityService.selectOne(id));
        return activityService.selectOne(id);
    }
}
